package FactoryMethod;

use JIP::ToolSet; # load my commonly-used modules in a single import
use English qw( -no_match_vars );

sub _isRequireError {
    my( $class, $requiredModule ) = @ARG;

    my $package = caller;

    # Try to deterine if we've been given a module name or file.
    # Module names must be barewords, files not.
    $requiredModule = qq['$requiredModule']
        unless _isModuleName( $requiredModule );

    local( $OS_ERROR, $EVAL_ERROR, $SIG{'__DIE__'} ); # isolate eval

    eval qq{
        package $package;
        require $requiredModule;
    };

    return unless $EVAL_ERROR;

    chomp $EVAL_ERROR;
    return $EVAL_ERROR;
}

sub _isModuleName {
    my $module = shift;

    # Module names start with a letter.
    # End with an alphanumeric.
    # The rest is an alphanumeric or ::
    $module =~ s/\b::\b//g;
    $module =~ /^[a-zA-Z]\w*$/;
}

sub _makePathToFile {
    my( $self, $name ) = @ARG;

    $name =~ s/::/\//g;

    return $name .'.pm';
}

1;
